# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libglade

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.6.4
pkgrel=2
pkgdesc="Allows you to load glade interface files in a program at runtime (mingw-w64)"
arch=(any)
url="http://www.gnome.org"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gtk2>=2.16.0" "${MINGW_PACKAGE_PREFIX}-libxml2>=2.7.3")
groups=("${MINGW_PACKAGE_PREFIX}")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2" "${MINGW_PACKAGE_PREFIX}-pkg-config")
optdepends=("${MINGW_PACKAGE_PREFIX}-python2: libglade-convert script")
options=('staticlibs' 'strip')
source=(http://ftp.gnome.org/pub/gnome/sources/${_realname}/2.6/${_realname}-${pkgver}.tar.bz2
    libglade-2.0.1-nowarning.patch
    libglade-secondary.patch
    libglade-link-against-gmodule.patch)
md5sums=('d1776b40f4e166b5e9c107f1c8fe4139'
         '4f879c0ce550004905aa0fb24f25c353'
         '833d0feb0ffb01d99577b7ab92dbea89'
         'cc84426b5fd975e5672a63409464bc33')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "$srcdir"/libglade-2.0.1-nowarning.patch
  patch -p1 -i "$srcdir"/libglade-link-against-gmodule.patch
  patch -p1 -i "$srcdir"/libglade-secondary.patch

  WANT_AUTOMAKE=latest autoreconf -fi
}

build() {
  [[ -d "$srcdir/build-${MINGW_CHOST}" ]] && rm -rf "$srcdir/build-${MINGW_CHOST}"
  cp -r "$srcdir/${_realname}-${pkgver}" "$srcdir/build-${MINGW_CHOST}"
  cd "$srcdir/build-${MINGW_CHOST}"

  PYTHON=${MINGW_PREFIX}/bin/python2 \
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}
  make
}

package() {
  cd "$srcdir/build-${MINGW_CHOST}"
  make DESTDIR="$pkgdir" install -j1
  install -m755 libglade-convert "${pkgdir}${MINGW_PREFIX}/bin/"
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
